/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 20:07:16
 * @LastEditTime: 2021-08-30 20:09:45
 * @LastEditors: changqing
 * @Usage: 
 */

var { of,Observable} = require('rxjs'); 
var {filter} = require('rxjs/operators');
const filterPassScore = (passScore) => {
  return (source$) => {
  // 创建新的 Observable
    return new Observable((subscriber) => {
    // 订阅來源 Observable并创建Observer来处理Observable的各种事件
      source$.subscribe({
        next: (score) => {
        if (score >= passScore) {
        // 分数及格 产生事件
        subscriber.next(score);
        }
        },
        // 也要处理 error 和 complete 事件
        error: (error) => subscriber.error(error),
        complete: () => subscriber.complete(),
      });
    });
  };
};

const scores = of( 80,36, 49, 100);
scores.pipe(filterPassScore(60)).subscribe(console.log);